// leftDIV
var aMenu={ 
	l:$('#menuB'),
	r:$('#right'),ro:1,
	h:$('#menu_fix')
};
aMenu.show = function(){
	if (!this.h.hasClass('fix')){
		this.l.show();
	}
	return this;
}
aMenu.hide = function(){
	if (!this.h.hasClass('fix')){
		this.l.hide();	
	}				
	return this;
}
aMenu.fix = function(b){
    var fb = this.h.hasClass('fix')?0:1;
	if (typeof(b)=='undefined')
		b = fb;
	else if(b!=fb)
    	return ;
    
    
	if(TEMP['menu-fix3'])TEMP['menu-fix3'].un();
	setTimeout(function(){ TEMP['menu-fix3'] = fixDIV('#menuH')}, 500);
    
	var rp = parseInt(this.r.css('margin-left')), w =this.l.outerWidth()+this.ro;
	if (b){
		this.show();
		this.h.addClass('fix');  //锁定标志
		this.r.css('margin-left',  rp+w);
	}else{	
		this.h.removeClass('fix');
		this.hide();	
		this.r.css('margin-left', rp-w);
	}
    localStorage.setItem('aMenu_fix', b);
}
$('#menuH').bind('mouseenter',function(){
    clearTimeout(TEMP['amenuhidetime']);
    aMenu.show();
}).bind('mouseleave',function(){
    TEMP['amenuhidetime'] = setTimeout(function(){aMenu.hide();},  300);
});


// load
$(document).ready(function(e) {
	var th=$('#top').height(), h=$('body').height()-th;
	$('#menuH').height(Math.max(200, $(window).height()-th));
	$('#main').height(Math.max(200, h));
	var a = localStorage.getItem('aMenu_fix');
    aMenu.fix(a==null ?1:a);
});

// 链接
$('#menu a').bind('click', function(e){
	var b=$(this).parent('p').next('.subTree');
	if (b.length<1)
        return aMenu.hide();
    e.stopPropagation();
    b.show();
});
$('#menu p').bind('click', function(){
    var a=$(this).next('.subTree'); 
    if (a.length)a.toggle();
});


// main 
$(function(){
	var u_pre; //显示的url
	var a=document.location.href, n=a.indexOf('#');
	var mainLink = '?u=cai-fmain';
	
	if (n<0){
		u_pre = a;
		a = mainLink;
	}else{
		u_pre = a.substr(0, n);
		a = a.substr(n+1);
	}
	
	$('#main').attr('src', ROOT_URL + a).bind('load',_ini);
	function _ini(){
		var f=$("#main"); fb=f[0].contentWindow, u = fb.document.location.href;
        if (u=='about:blank' || u== ROOT_URL + mainLink)
			return;

		a = u.replace(ROOT_URL, '');
		document.location.href = u_pre +'#'+ a;
		var t = fb.document.title;
		if(t) document.title = t;
	}
});